home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 11 / FM Towns Free Software Collection 11.iso / t_os / tool / artemis1 / src / mainmenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-08  |  19.8 KB  |  773 lines

  1. /*
  2.     ARTemis (Graphic Editor for FM-TOWNS)
  3.     (c) MATSUUCHI Ryosuke 1992
  4.  
  5.     mainmenu.c
  6. */
  7.  
  8. // #define DEBUG
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13. #include <stdlib.h>
  14. #include <egb.h>
  15. #include <mos.h>
  16.  
  17. #include "ge.h"
  18. #include "plt16.h"
  19. #include "imageman.h"
  20. #include "dispman.h"
  21. #include "mask.h"
  22. #include "colspace.h"
  23.  
  24. /*--------------------------------------------------------*/
  25. /*             パレットとRGBとHLSの取扱             */
  26. /*--------------------------------------------------------*/
  27.  
  28. static int  __plt[PLTNUM];
  29. static deci __h[PLTNUM];
  30.  
  31. void plt_init(void)
  32. {
  33.     static    int        _plt32K[] =
  34.         { 0, 0, GRB(21, 0, 0), GRB(31,20,10),
  35.           GRB( 0, 0,31), GRB(13, 5,31), GRB( 0,22, 0), GRB(23, 3,31),
  36.           GRB( 6,31, 0), GRB(16,31, 5), GRB(31,31, 0), GRB(23,31,19),
  37.           GRB(10, 0, 0), GRB( 0,31,31), GRB(14,14,14), GRB(31,31,31) };
  38.     memcpy(__plt, _plt32K, sizeof(int)*16);
  39.     int i;
  40.     for (i=0; i<PLTNUM; i++)
  41.         __h[i] = -1;
  42. }
  43.  
  44. int plt_getcode(int pltcode)
  45. {
  46.     return __plt[pltcode];
  47. }
  48.  
  49. void plt_setcode(int pltcode, int colcode)
  50. {
  51.     __plt[pltcode] = colcode;
  52.     deci h,l,s;
  53.     #define C colcode
  54.     rgb_hls(getR(C),getG(C),getB(C), &h,&l,&s);
  55.     #undef C
  56.     if(s>0)
  57.         __h[pltcode] = h;
  58. }
  59.  
  60. #define P    __plt[plt]
  61.  
  62. void plt_getRGB(int plt, int *r, int *g, int *b)
  63. {
  64.     *r=getR(P), *g=getG(P), *b=getB(P);
  65. }
  66.  
  67. void plt_setRGB(int plt,int r,int g,int b)
  68. {
  69.     P = GRB(g,r,b);
  70.     deci h,l,s;
  71.     rgb_hls(r,g,b,&h,&l,&s);
  72.     if(s>0)
  73.         __h[plt] = h;
  74. }
  75.  
  76. void plt_getHLS(int plt,deci *h,deci *l,deci *s)
  77. {
  78.     int r,g,b;
  79.     r=getR(P),g=getG(P),b=getB(P);
  80.     rgb_hls(r,g,b,h,l,s);
  81.     if(__h[plt]>=0)
  82.         *h = __h[plt];
  83. }
  84.  
  85. void plt_setHLS(int plt,deci h,deci l,deci s)
  86. {
  87.     int r,g,b;
  88.     hls_rgb(h,l,s,&r,&g,&b);
  89.     P = GRB(g,r,b);
  90.     __h[plt] = h;
  91. }
  92.  
  93. void plt_setH(int plt, deci _h)
  94. {
  95.     int r,g,b;
  96.     deci h,l,s;
  97.     r=getR(P),g=getG(P),b=getB(P);
  98.     rgb_hls(r,g,b,&h,&l,&s);
  99.     h = _h;
  100.     hls_rgb(h,l,s,&r,&g,&b);
  101.     P = GRB(g,r,b);
  102.     __h[plt] = _h;
  103. }
  104.  
  105. void plt_setL(int plt, deci _l)
  106. {
  107.     int r,g,b;
  108.     deci h,l,s;
  109.     r=getR(P),g=getG(P),b=getB(P);
  110.     rgb_hls(r,g,b,&h,&l,&s);
  111.     l = _l;
  112.     hls_rgb((__h[plt]>=0 ? __h[plt] : h),l,s,&r,&g,&b);
  113.     P = GRB(g,r,b);
  114. }
  115.  
  116. void plt_setS(int plt, deci _s)
  117. {
  118.     int r,g,b;
  119.     deci h,l,s;
  120.     r=getR(P),g=getG(P),b=getB(P);
  121.     rgb_hls(r,g,b,&h,&l,&s);
  122.     s = _s;
  123.     hls_rgb((__h[plt]>=0? __h[plt] : h),l,s,&r,&g,&b);
  124.     P = GRB(g,r,b);
  125. }
  126.  
  127. #undef P
  128.  
  129. /*--------------------------------------------------------*/
  130. /*                 カラーバー(RGB/HLS)                  */
  131. /*--------------------------------------------------------*/
  132.  
  133. #include "colbar.md"
  134.  
  135. static    SCROLLBAR    *_sp;
  136. static    int            _pltcode;
  137.  
  138. void colbar_disp(int x, int y, SCROLLBAR *sp, int pltcode)
  139. {
  140.     _pltcode = pltcode;
  141.     int initcode[3];
  142.     if (colmodel == MODEL_RGB)
  143.         plt_getRGB(pltcode,&initcode[0],&initcode[1],&initcode[2]);
  144.     else
  145.     {
  146.         int h,l,s;
  147.         plt_getHLS(pltcode,&h,&l,&s);
  148.         initcode[0] = _lim(DI(99 * h),0,99);
  149.         initcode[1] = _lim(DI(99 * l),0,99);
  150.         initcode[2] = _lim(DI(99 * s),0,99);
  151.     }
  152.     int mx,my;
  153.     menu_getmenuxy(NULL, &mx, &my, NULL, NULL);
  154.     _sp = sp;
  155.     int i;
  156.     for (i=0; i<3; i++)
  157.     {
  158.         #define S    _sp[i]
  159.         S = RGBHLSbar[i];
  160.         menu_scrollbar_setxy(&S,x+i*15,y);
  161.         if (colmodel == MODEL_RGB)
  162.             menu_scrollbar_setallsize(&S,31+5),
  163.             menu_scrollbar_setdispsize(&S,5);
  164.         else
  165.             menu_scrollbar_setallsize(&S,99+16),
  166.             menu_scrollbar_setdispsize(&S,16);
  167.         menu_scrollbar_setvar(&S,initcode[i]);
  168.         menu_drawscrollbar(&S);
  169.         int tx,ty,tlen;
  170.         menu_scrollbar_getxy(&S,&tx,&ty,&tlen);
  171.         ty += tlen+1+13;
  172.         grboxfill(tx,ty,12,12,menu_plt(COL_menu),DrawNORMAL);
  173.         char *s[2][3] = {{"R","G","B"},{"H","L","S"}};
  174.         ARTputstr12(tx,ty,(colmodel==MODEL_RGB?s[0][i]:s[1][i]),
  175.                     menu_plt(COL_menuString),menu_plt(COL_menu));
  176.         #undef S
  177.     }
  178. }
  179.  
  180. void colbar_erase(void)
  181. {
  182.     int i;
  183.     for (i=0; i<3; i++)
  184.     {
  185.         #define S    _sp[i]
  186.         S = RGBHLSnullbar[i];
  187.         #undef S
  188.     }
  189. }
  190.  
  191. void colbar_makeup(void)
  192. {
  193.     #define SETBV(n,a)   menu_scrollbar_setvar(&_sp[n],a)
  194.     if (colmodel == MODEL_RGB)
  195.     {
  196.         int r,g,b;
  197.         plt_getRGB(_pltcode, &r,&g,&b);
  198.         SETBV(0,r);
  199.         SETBV(1,g);
  200.         SETBV(2,b);
  201.     }
  202.     else
  203.     {
  204.         deci h,l,s;
  205.         plt_getHLS(_pltcode, &h,&l,&s);
  206.         SETBV(0,_lim(DI(99*h),0,99));
  207.         SETBV(1,_lim(DI(99*l),0,99));
  208.         SETBV(2,_lim(DI(99*s),0,99));
  209.     }
  210.     menu_makeupscrollbar(&_sp[0]);
  211.     menu_makeupscrollbar(&_sp[1]);
  212.     menu_makeupscrollbar(&_sp[2]);
  213.     #undef BV
  214. }
  215.  
  216. void colbar_setpltcode(int pltcode)
  217. {
  218.     _pltcode = pltcode;
  219.     colbar_makeup();
  220. }
  221.  
  222. int colbar_getpltcode(void)
  223. {
  224.     return _pltcode;
  225. }
  226.  
  227. void colbar_attachfunc(void (*func)())    // 更新関数の登録
  228. {
  229.     int i;
  230.     for (i=0; i<3; i++)
  231.     {
  232.         #define S    _sp[i]
  233.         menu_scrollbar_setfunc(&S, func);
  234.         #undef S
  235.     }
  236. }
  237.  
  238. void colbar_getRGB(int *r, int *g, int *b)
  239. {
  240.     #define BV(n)    menu_scrollbar_getvar(&_sp[n])
  241.     if (colmodel == MODEL_RGB)
  242.         *r = BV(0),
  243.         *g = BV(1),
  244.         *b = BV(2);
  245.     else
  246.     {
  247.         deci h,l,s;
  248.         h = _lim((ID(BV(0))+FD(0.5)) / 99, 0, ID(1));
  249.         l = _lim((ID(BV(1))+FD(0.5)) / 99, 0, ID(1));
  250.         s = _lim((ID(BV(2))+FD(0.5)) / 99, 0, ID(1));
  251.         hls_rgb(h,l,s,r,g,b);
  252.     }
  253.     #undef BV
  254. }
  255.  
  256. /*--------------------------------------------------------*/
  257. /*                  メインメニューの定義                  */
  258. /*--------------------------------------------------------*/
  259.  
  260. #if 0
  261. enum {
  262.     itemPenSample=0,    itemView,        itemColList,
  263.     itemForeCol,        itemBackCol,    itemCmdColspace,    itemMixrate,
  264.     itemIcons,
  265.  
  266.     itemCmdPFLine,        itemCmdPFPset,    itemCmdLine,        itemCmdBlot,
  267.     itemCmdSpray,        itemCmdBoxfill,    itemCmdPoly,
  268.  
  269.     itemCmdPaint,        itemCmdGoshi,    itemCmdSmooth,        itemCmdCopy,
  270.     itemCmdCopyPoly,    itemCmdZoom,    itemCmdZoomPoly,
  271.  
  272.     itemCmdDiffuse,        itemCmdDiffuseA,    itemCmdSharp,
  273.     itemCmdCopyBoxHturn,    itemCmdCopyBoxVturn,
  274.     itemCmdCopyPolyHturn,    itemCmdCopyPolyVturn,
  275.     
  276.     itemCmdSand,        itemCmdSandA,    itemCmdColchg,
  277.     itemCmdRotateBox,    itemCmdRotatePoly,
  278.     itemCmdSave,        itemCmdLoad,
  279.  
  280.     itemCmdUndo,        itemCmdView,        itemCmdPat,        itemCmdSetup,
  281.     itemCmdMask,        itemCmdTest,        itemCmdExit,
  282.  
  283.     /* itemCmdAccent, itemCmdPlay, itemCmdRec, itemCmdRecStop, */
  284.     itemEND
  285. };
  286. #endif
  287.  
  288. #define    COLBARX    176
  289. #define    COLBARY    24
  290.  
  291. static void disp_mainmenu(), erase_mainmenu();
  292. static void touchRGBbars(),touchMixbar();
  293. static void touchRGBbars();
  294.  
  295. #include "mainmenu.md"
  296.  
  297. #define    BAR(n)    &mainmenu_bars[n]
  298. #define    MAINMIP(n)    (&mainmenu.itemlist[(n)])    /* MAIN Menu Item Pointer */
  299.  
  300. static    void    drawViewCsr(int col),eraseViewCsr();
  301. static    int        drawCols();
  302. static    void    eraseCols(), drawColCsr();
  303. void cols_init(int *col1,int *col2, MENU *menu, int itemcol1, int itemcol2);
  304.  
  305.  
  306. static void disp_mainmenu()
  307. {
  308.     int ix,iy,ixlen,iylen;
  309.     menu_getbuttonxy(&mainmenu, itemColList, &ix, &iy, NULL, NULL);
  310.     drawPltList(ix,iy);
  311.     drawPltCsr(pltnum);
  312.     drawViewCsr(White);
  313.     menu_getbuttonxy(&mainmenu, itemPenSample, &ix, &iy, &ixlen,&iylen);
  314.     grboxfill(ix,iy,ixlen,iylen,menu_plt(White),DrawNORMAL);
  315.     grboxline(ix,iy,ixlen,iylen,menu_plt(Black),DrawNORMAL);
  316.     pen_display(getcurpen(),ix+(ixlen-32)/2, iy+(iylen-32)/2);
  317.     cols_init(&forecol,&backcol, &mainmenu, itemForeCol, itemBackCol);
  318.     colbar_disp(COLBARX, COLBARY, BAR(0), pltnum);
  319.     drawCols();
  320.     drawColCsr();
  321.     colbar_attachfunc(touchRGBbars);
  322. }
  323.  
  324.  
  325. static void erase_mainmenu()
  326. {
  327.     colbar_erase();
  328.     erasePltList();
  329.     eraseViewCsr();
  330.     eraseCols();
  331. }
  332.  
  333. /*--------------------------------------------------------*/
  334. /*              メインメニューの更新ルーチン              */
  335. /*--------------------------------------------------------*/
  336.  
  337.  
  338. // ● ビューカーソルの描画・消去
  339.  
  340. static bool viewcsr_on = NO;
  341. static int  viewcsr_x, viewcsr_y, viewcsr_xlen, viewcsr_ylen;
  342. static int  viewcsr_col;
  343.  
  344.  
  345. static void eraseViewCsr()
  346. {
  347.     if (!viewcsr_on)
  348.         return;
  349.     int ix,iy;
  350.     menu_getbuttonxy(&mainmenu, itemView, &ix, &iy, NULL, NULL);
  351.     grboxline(ix + viewcsr_x, iy + viewcsr_y,
  352.               viewcsr_xlen, viewcsr_ylen, DMgetmenuplt(Black), DrawNORMAL);
  353.     viewcsr_on = NO;
  354. }
  355.  
  356.  
  357. static void getviewcsrpossize(int *x, int *y, int *xlen, int *ylen)
  358. {
  359.     int ix,iy,ixlen,iylen;
  360.     menu_getbuttonxy(&mainmenu, itemView, &ix, &iy, &ixlen, &iylen);
  361.     int dispx,dispy,dispxlen,dispylen;
  362.     DMimage_getdispxy(&dispx,&dispy);
  363.     DMimage_getdispxylen(&dispxlen,&dispylen);
  364.     *x = ix + dispx * ixlen / EIMgetxsize();
  365.     *y = iy + dispy * iylen / EIMgetysize();
  366.     *xlen = _max(1,dispxlen * ixlen / EIMgetxsize());
  367.     *ylen = _max(1,dispylen * iylen / EIMgetysize());
  368.     return;
  369. }
  370.  
  371.  
  372. static void drawViewCsr(int col)
  373. {
  374.     int ix,iy,ixlen,iylen;
  375.     menu_getbuttonxy(&mainmenu, itemView, &ix, &iy, &ixlen, &iylen);
  376.     // 以下の5行で、ビューカーソルの表示位置・大きさを計算する
  377.     int x,y,xlen,ylen,dispx,dispy,dispxlen,dispylen;
  378.     DMimage_getdispxy(&dispx,&dispy);
  379.     DMimage_getdispxylen(&dispxlen,&dispylen);
  380.     x = dispx * ixlen / EIMgetxsize();
  381.     y = dispy * iylen / EIMgetysize();
  382.     xlen = _max(1,dispxlen * ixlen / EIMgetxsize());
  383.     ylen = _max(1,dispylen * iylen / EIMgetysize());
  384.     if (/* ビューカーソルの表示を変更する必要がないならば */
  385.         viewcsr_on && viewcsr_x == x && viewcsr_y == y &&
  386.         viewcsr_xlen == xlen && viewcsr_ylen == ylen && viewcsr_col == col)
  387.     {
  388.          return;
  389.     }
  390.     eraseViewCsr();
  391.     grboxline(ix + x, iy + y, xlen, ylen, DMgetmenuplt(col), DrawNORMAL);
  392.     viewcsr_x = x;
  393.     viewcsr_y = y;
  394.     viewcsr_xlen = xlen;
  395.     viewcsr_ylen = ylen;
  396.     viewcsr_col = col;
  397.     viewcsr_on = YES;
  398. }
  399.  
  400. static void touchRGBbars(void)
  401. {
  402.     int r,g,b;
  403.     colbar_getRGB(&r,&g,&b);
  404.     plt_setRGB(pltnum, r,g,b);
  405.     makeupPltList();
  406.     if (cols_getcsrpos() == 0)
  407.         forecol = plt_getcode(pltnum);
  408.     else
  409.         backcol = plt_getcode(pltnum);
  410.     makeupCols();
  411. }
  412.  
  413. static void touchMixbar(void)
  414. {
  415.     mixrate = menu_scrollbar_getvar(BAR(3));
  416. }
  417.  
  418. /*--------------------------------------------------------*/
  419. /*                  メニューの項目を実行                  */
  420. /*--------------------------------------------------------*/
  421.  
  422.  
  423. extern void commandSave(),     commandLoad(),     commandCopy(), commandView();
  424. extern void commandSetup(),     commandPaint(), commandLine(), commandSpray();
  425. extern void commandPFline(), commandPFPset(),setPen(),        commandBoxfill();
  426. extern void commandPattern(),commandAccent(),commandZoom(), commandUndo();
  427. extern void commandBlot(),   commandDiffuse(),commandSand();
  428. extern void cmd_polygon(),   commandGoshi(),  commandMsPlay(),commandMsRec();
  429. extern void commandMsRecStop();
  430. extern void commandDiffuseArea(),commandSandArea(),commandSmooth();
  431. extern void commandRotatePoly(),commandCopyPoly();
  432. extern void commandZoomPoly(),commandRotateBox();
  433. extern void commandColchg(),commandSharp();
  434. extern void commandCopyHturn(),commandCopyVturn();
  435. extern void commandCopyPolyHturn(),commandCopyPolyVturn();
  436. extern void commandMask();
  437. extern void commandColspace();
  438. extern void commandFreeTest();
  439.  
  440.  
  441. static int execMainMenuItems(int itemnum)
  442. // 返値: -1 itemnum に該当する項目がなかった
  443. //          0 該当する項目が存在したので、それを実行した
  444. {
  445.     DEBUG_MSG("execMainMenuItems begin");
  446.  
  447.     typedef struct
  448.     {
  449.         #ifdef DEBUG
  450.         char *name;            // デバッグ用のコマンド名文字列
  451.         #endif
  452.         short int item;        // 対応するアイテム番号(-1 : エンドマーク)
  453.         char type;            // 0=メニューを消して、画面を保存して実行
  454.                             // 1=メニューを消し、画面を保存しないで実行
  455.                             // 2=メニューを消さずに実行
  456.         void (*func)();        // 実行する関数
  457.     } EXEC;
  458.  
  459.     static EXEC execlist[] =
  460.     {
  461.         #ifdef DEBUG
  462.             #define    EE(a,b,c,d)        { a,b,c,d }
  463.         #else
  464.             #define EE(a,b,c,d)        { b,c,d }
  465.         #endif
  466.         EE( "セーブ",        itemCmdSave,        0,    commandSave        ),
  467.         EE( "ロード",        itemCmdLoad,        0,    commandLoad        ),
  468.         EE( "コピー",        itemCmdCopy,        1,    commandCopy        ),
  469.         EE( "ビュー",        itemCmdView,        1,    commandView        ),
  470.         EE( "設定",            itemCmdSetup,        1,    commandSetup    ),
  471.         EE("閉領域フィル",    itemCmdPaint,        1,    commandPaint    ),
  472.         EE( "直線",            itemCmdLine,        1,    commandLine        ),
  473.         EE( "スプレー",        itemCmdSpray,        1,    commandSpray    ),
  474.         EE( "自由曲線",        itemCmdPFLine,        1,    commandPFline    ),
  475.         EE( "自由点描",        itemCmdPFPset,        1,    commandPFPset    ),
  476.         EE( "ペン先編集",    itemPenSample,        1,    setPen            ),
  477.         EE( "矩形フィル",    itemCmdBoxfill,        1,    commandBoxfill    ),
  478.         EE("パターン編集",    itemCmdPat,            1,    commandPattern    ),
  479.         // EE("アクセント",    itemCmdAccent,        0,    commandAccent    ),
  480.         EE( "拡大縮小",        itemCmdZoom,        1,    commandZoom        ),
  481.         EE( "アンドゥー",    itemCmdUndo,        1,    commandUndo        ),
  482.         EE( "にじみペン",    itemCmdBlot,        1,    commandBlot        ),
  483.         EE( "ぼかしペン",    itemCmdDiffuse,        1,    commandDiffuse    ),
  484.         EE( "砂ペン",        itemCmdSand,        1,    commandSand        ),
  485.         EE("ポリゴンフィル",itemCmdPoly,        1,    cmd_polygon        ),
  486.         EE( "こすりペン",    itemCmdGoshi,        1,    commandGoshi    ),
  487.         // EE( "MSPLAY",    itemCmdPlay,        2,    commandMsPlay    ),
  488.         // EE( "MSREC",        itemCmdRec,            2,    commandMsRec    ),
  489.         // EE( "MSRECSTOP",    itemCmdRecStop,        2,    commandMsRecStop),
  490.         EE( "領域ぼかし",    itemCmdDiffuseA,    1,    commandDiffuseArea),
  491.         EE( "領域砂化",        itemCmdSandA,        1,    commandSandArea ),
  492.         EE( "領域平滑",        itemCmdSmooth,        1,    commandSmooth ),
  493.         EE( "矩形回転",        itemCmdRotateBox,    1,    commandRotateBox ),
  494.         EE( "多角形回転",    itemCmdRotatePoly,    1,    commandRotatePoly ),
  495.         EE( "多角形拡大",    itemCmdZoomPoly,    1,    commandZoomPoly ),
  496.         EE( "多角形コピー",    itemCmdCopyPoly,    1,    commandCopyPoly ),
  497.         EE( "色彩変換",        itemCmdColchg,        1,    commandColchg ),
  498.         EE( "シャープ化",    itemCmdSharp,        1,    commandSharp ),
  499.         EE( "左右反転BOX",    itemCmdCopyBoxHTurn,  1,commandCopyHturn ),
  500.         EE( "上下反転BOX",    itemCmdCopyBoxVTurn,  1,commandCopyVturn ),
  501.         EE( "左右反転POLY",    itemCmdCopyPolyHTurn, 1,commandCopyPolyHturn ),
  502.         EE( "上下反転POLY",    itemCmdCopyPolyVTurn, 1,commandCopyPolyVturn ),
  503.         EE( "マスク",        itemCmdMask,        1, commandMask ),
  504.         EE( "テスト",        itemCmdTest,        1, commandFreeTest ),
  505.         EE( "色空間",        itemCmdColSpace,    1, commandColspace ),
  506.         EE( "",-1,-1,NOFNC )
  507.         #undef EE
  508.     };
  509.  
  510.     EXEC *ep;
  511.     for (ep = execlist;  ep->item != -1;  ep++)
  512.     {
  513.         if (ep->item == itemnum)
  514.         {
  515.             switch (ep->type)
  516.             {
  517.             case 0:
  518.                 #ifdef DEBUG
  519.                 sprintf(debugmsg, "(execMainMenuItems) type 0 command:[%s]",
  520.                         ep->name);
  521.                 DEBUG_MSG(debugmsg);
  522.                 #endif
  523.                 DEBUG_MSG("これよりメニューを消去");
  524.                 menu_erase();
  525.                 DEBUG_MSG("これより編集バッファを退避");
  526.                 EIMbackup();
  527.                 DEBUG_MSG("退避完了");
  528.                 break;
  529.             case 1:
  530.                 #ifdef DEBUG
  531.                 sprintf(debugmsg, "(execMainMenuItems) type 1 command:[%s]",
  532.                         ep->name);
  533.                 DEBUG_MSG(debugmsg);
  534.                 #endif
  535.                 menu_erase();
  536.             }
  537.             if (ep->func != NOFNC)
  538.                 (*ep->func)();
  539.             if (cols_getcsrpos() == 0)
  540.                 forecol = plt_getcode(pltnum);
  541.             else
  542.                 backcol = plt_getcode(pltnum);
  543.             switch (ep->type)
  544.             {
  545.             case 0:
  546.                 menu_disp(&mainmenu);
  547.                 break;
  548.             case 1:
  549.                 menu_disp(&mainmenu);
  550.             }
  551.             DEBUG_MSG("execMainMenuItems end");
  552.             return 0;
  553.         }
  554.     }
  555.     DEBUG_MSG("execMainMenuItems end");
  556.     return -1;
  557. }
  558.  
  559.  
  560.  
  561.  
  562. /*--------------------------------------------------------*/
  563. /*                view box によるスクロール               */
  564. /*--------------------------------------------------------*/
  565.  
  566.  
  567. static void touch_view(void)
  568. {
  569.     int ix,iy,ixlen,iylen;
  570.     menu_getbuttonxy(&mainmenu, itemView, &ix, &iy, &ixlen, &iylen);
  571.     int dispxlen,dispylen;
  572.     DMimage_getdispxylen(&dispxlen,&dispylen);
  573.     int vx,vy,vxlen,vylen;
  574.     getviewcsrpossize(&vx,&vy,&vxlen,&vylen);
  575.     if (!(vx <= ms.x && ms.x < vx+vxlen && vy <= ms.y && ms.y < vy+vylen))
  576.     {
  577.         int dispx, dispy;
  578.         dispx = ((ms.x - vxlen / 2 - ix) * EIMgetxsize() + ixlen / 2) / ixlen;
  579.         dispy = ((ms.y - vylen / 2 - iy) * EIMgetysize() + iylen / 2) / iylen;
  580.         DMimage_limitdispxy(dispx,dispy,&dispx,&dispy);
  581.         DMimage_setdispxy(dispx,dispy);
  582.         getviewcsrpossize(&vx,&vy,&vxlen,&vylen);
  583.     }
  584.     int rx = ms.x - vx, ry = ms.y - vy;
  585.     drawViewCsr(Yellow);
  586.     while (ms.btn1 == OFFON || ms.btn1 == ON)
  587.     {
  588.         int predispx, predispy, dispx, dispy;
  589.         DMimage_getdispxy(&predispx,&predispy);
  590.         DMdispcsr(ms.x,ms.y);
  591.         for (;;)
  592.         {    ms_get(&ms);
  593.             if (ms.dx!=0||ms.dy!=0||(ms.btn1==ONOFF||ms.btn1==OFF)||
  594.                 ms.btn2!=OFF||key_chk()!=0) break; }
  595.         DMerasecsr();
  596.         limitCsrPos();
  597.         dispx = ((ms.x - rx - ix) * EIMgetxsize() + ixlen / 2) / ixlen;
  598.         dispy = ((ms.y - ry - iy) * EIMgetysize() + iylen / 2) / iylen;
  599.         DMimage_limitdispxy(dispx,dispy,&dispx,&dispy);
  600.         if (dispx != predispx || dispy != predispy)
  601.             DMimage_setdispxy(dispx,dispy);
  602.         drawViewCsr(Yellow);
  603.     }
  604.     limitCsrPos();
  605.     drawViewCsr(White);
  606. }
  607.  
  608.  
  609. /*--------------------------------------------------------*/
  610. /*                         メイン                         */
  611. /*--------------------------------------------------------*/
  612.  
  613.  
  614. void do_mainmenu(void)
  615. {
  616.     // mainmenu.x0 = ((DMimage_getzoomrate()==1? 512: 640) - mainmenu.xlen) / 2;
  617.     // mainmenu.y0 = (480                                  - mainmenu.ylen) / 2;
  618.     menu_scrollbar_setvar(BAR(3),mixrate);
  619.     // menu_dispxy(-2,-2,&mainmenu);
  620.     menu_dispxy(-3,-3,&mainmenu);
  621.     int prex,prey;    // 自由曲線描画のための前座標保存変数
  622.     for (;;)
  623.     {
  624.         DMdispcsr(ms.x,ms.y);
  625.         drawViewCsr(White);
  626.         for (;;)
  627.         {
  628.             ms_get(&ms);
  629.             if (ms.dx!=0||ms.dy!=0||ms.btn1!=OFF||ms.btn2!=OFF||key_chk()!=0)
  630.                 break;
  631.         }
  632.         DMerasecsr();
  633.         scrollForCsr(1,1);
  634.         if (ms.btn1 == OFFON)
  635.         {
  636.             int a;  int ax,ay;  SCROLLBAR *sbarp;
  637.             a = menu_where(ms.x,ms.y,&mainmenu, &ax,&ay,&sbarp);
  638.             prex = prey = -1;
  639.             switch (a)
  640.             {
  641.             case OutOfMenu:
  642.                 prex = DMimage_getx(ms.x), prey = DMimage_gety(ms.y);
  643.                 EIMpset(prex,prey,forecol,DrawNORMAL);
  644.                 break;
  645.             case itemColList:
  646.                 drawPltCsr(pltnum);    // erase
  647.                 pltnum = ax/16 + (ay/16)*4;
  648.                 // makeupRgbBar();
  649.                 drawPltCsr(pltnum);    // draw
  650.                 // drawColCsr();
  651.                 // eraseCols();
  652.                 colbar_setpltcode(pltnum);
  653.                 if (cols_getcsrpos() == 0)
  654.                     forecol = plt_getcode(pltnum);
  655.                 else
  656.                     backcol = plt_getcode(pltnum);
  657.                 makeupCols();
  658.                 // drawCols();
  659.                 // drawColCsr();
  660.                 break;
  661.             case itemForeCol:
  662.                 drawColCsr();
  663.                 cols_setcsrpos(0);
  664.                 drawColCsr();
  665.                 break;
  666.             case itemBackCol:
  667.                 drawColCsr();
  668.                 cols_setcsrpos(1);
  669.                 drawColCsr();
  670.                 break;
  671. /*
  672.             case itemRgbBar:
  673.                 touchRgbBar(ax,ay,ms.btn1);
  674.                 if (cols_getcsrpos() == 0)
  675.                     forecol = plt_getcode(pltnum);
  676.                 else
  677.                     backcol = plt_getcode(pltnum);
  678.                 makeupCols();
  679.                 break;
  680. */
  681.             case itemCmdExit:
  682.                 menu_erase();
  683.                 extern int commandExit();
  684.                 if (commandExit() == 0)
  685.                     goto EXIT;
  686.                 menu_disp(&mainmenu);
  687.                 break;
  688.             case itemScrollBar:
  689.                 menu_touchscrollbar(sbarp, ax,ay);
  690.                 if (cols_getcsrpos() == 0)
  691.                     forecol = plt_getcode(pltnum);
  692.                 else
  693.                     backcol = plt_getcode(pltnum);
  694.                 makeupCols();
  695.                 break;
  696.             case itemMoveMenu:
  697.                 menu_move();
  698.                 break;
  699.             case itemView:
  700.                 touch_view();
  701.                 break;
  702.             default:
  703.                 execMainMenuItems(a);
  704.             }
  705.         }
  706.         else if (ms.btn1 == ON)
  707.         {
  708.             int a;  int ax,ay;
  709.             a = menu_where(ms.x,ms.y,&mainmenu, &ax,&ay,NULL);
  710.             if (a != OutOfMenu)
  711.                 prex = prey = -1;
  712.             switch (a)
  713.             {
  714.             case OutOfMenu:
  715.                 {
  716.                     int nx,ny;
  717.                     nx = DMimage_getx(ms.x);
  718.                     ny = DMimage_gety(ms.y);
  719.                     if (prex >= 0 && (prex!=nx || prey!=ny))
  720.                     {
  721.                         // printf("line:%d,%d,%d,%d\n",prex,prey,nx,ny);
  722.                         EIMline(prex,prey,nx,ny,forecol,DrawNORMAL);
  723.                     }
  724.                     else
  725.                         EIMpset(nx,ny,forecol,DrawNORMAL);
  726.                     prex = nx;
  727.                     prey = ny;
  728.                 }
  729.                 break;
  730. /*
  731.             case itemRgbBar:
  732.                 touchRgbBar(ax,ay,ms.btn1);
  733.                 if (cols_getcsrpos() == 0)
  734.                     forecol = plt_getcode(pltnum);
  735.                 else
  736.                     backcol = plt_getcode(pltnum);
  737.                 makeupCols();
  738. */
  739.             }
  740.         }
  741.         else if (ms.btn2 == OFFON)
  742.         {
  743.             int a;
  744.             a = menu_where(ms.x,ms.y,&mainmenu, NULL,NULL,NULL);
  745.             if (a == OutOfMenu)
  746.             {
  747.                 int px,py;
  748.                 px = DMimage_getx(ms.x),  py = DMimage_gety(ms.y);
  749.                 drawPltCsr(pltnum);    // erase
  750.                 if (mode == MODE32K)
  751.                     plt_setcode(pltnum, EIMpoint(px,py));
  752.                 else
  753.                     pltnum = EIMpoint(px,py);
  754.                 colbar_setpltcode(pltnum);
  755.                 makeupPltList();
  756.                 // makeupRgbBar();
  757.                 drawPltCsr(pltnum);    // draw
  758.                 drawColCsr();
  759.                 if (cols_getcsrpos() == 0)
  760.                     forecol = plt_getcode(pltnum);
  761.                 else
  762.                     backcol = plt_getcode(pltnum);
  763.                 makeupCols();
  764.                 drawColCsr();
  765.             }
  766.         }
  767.     }
  768. EXIT:
  769.     return;
  770. }
  771.  
  772. /* end of mainmenu.c */
  773.